//获取应用实例
const request = require('../../../../../utils/request');
Page({
    //初始化数据
    data: {
        passWordType: '',
        val: '',
        nextVal: '',
        oldPayword: 0
    },
    //获取链接参数
    onLoad: function (e){
        this.setData({
            passWordType: e.type
        })
        
    },
    onReady: function(){
        wx.setNavigationBarTitle({
            title: '密码'
          }) 
    },
    input1(e) {
        this.setData({
            val: e.detail.value
        })
    },
    input2(e) {
        this.setData({
            nextVal: e.detail.value
        })
    },
    inputOld(e) {
        this.setData({
            oldPayword: e.detail.value
        })
    },
    sendPassWord() {
        console.log(this.data.val+"====="+this.data.nextVal)
        let reg = /^[0-9]*$/;
        let url = '';
        if(!reg.test(this.data.val) || !reg.test(this.data.nextVal)) {
            wx.showModal({
                title: '提示',
                content: '请输入正确的密码',
                showCancel: true
            })
        }else if(this.data.val != this.data.nextVal) {
            wx.showModal({
                title: '提示',
                content: '两次密码不相等',
                showCancel: true
            })
        } else{
            if(this.data.passWordType == 'set'){
                url = 'user/setpayword';
                request.HttpRequst(true,url,false,'',{"payword": this.data.val,"cpayword": this.data.nextVal, 'token': wx.getStorageSync('sessionId') },"POST",false,res => { 
                    console.log(res)              
                    wx.showModal({
                        title: '提示',
                        content: res.info,
                        showCancel: true
                    })
                })
            }else {
                url = 'user/updatepayword';
                request.HttpRequst(true,url,false,'',{"oldPayword": this.data.oldPayword,"newPayword": this.data.val,"cnewPayword": this.data.nextVal, 'token': wx.getStorageSync('sessionId') },"POST",false,res => { 
                    console.log(res)              
                    wx.showModal({
                        title: '提示',
                        content: res.info,
                        showCancel: true
                    })
                })
            }
            
        }
        
    }

})